package cn.edu.jxau.test;

import java.util.ArrayList;
import java.util.List;

/**
 * 牛顿迭代
 * @author 付大石
 */
public class Main {

    public static void main(String[] args) {
        
        System.out.println(sqrt(4));
        System.out.println(sqrt(9));
        System.out.println(sqrt(16));
    }

    private static double sqrt(double x) {

        double precision = 1e-5; // 精度
        double t = x;
        while (Math.abs(t - x / t) > precision) {
            t = (t + x / t) / 2;
        }
        return t;
    }
}
